
package com.face.face.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.face.face.R;
import com.poya.bankcertificationsdk.model.constant.ExternalConstant;
import com.poya.bankcertificationsdk.view.activity.TakeFaceActivity;

public class LoginActivity extends BaseActivity implements View.OnClickListener {

    private final static int SIGN_CODE_01 = 9001;
    private final static int SIGN_CODE_02 = 9002;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        initPermissions();

        findViewById(R.id.zc).setOnClickListener(this);
        findViewById(R.id.rz).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.zc:
                _zc();
                break;
            case R.id.rz:
                _rz();
                break;
        }
    }

    private void _zc() {
        TakeFaceActivity.startActivityForResult(this, SIGN_CODE_01);
    }

    private void _rz() {
        TakeFaceActivity.startActivityForResult(this, SIGN_CODE_02);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == SIGN_CODE_01) {
            boolean success = data.getBooleanExtra(ExternalConstant.TAKE_IMAGE_SUCCESS_KEY, false);
            if (success) {
                String imagePath = data.getStringExtra(ExternalConstant.FACE_IMAGE_PATH_KEY);
                Intent intent = new Intent(LoginActivity.this, ZcActivity.class);
                Bundle bundle = new Bundle();
                bundle.putString("imagePath", imagePath);
                intent.putExtras(bundle);
                startActivity(intent);
                overridePendingTransition(R.anim.alpha_in, R.anim.alpha_out);
            }
        } else if (requestCode == SIGN_CODE_02) {
            boolean success = data.getBooleanExtra(ExternalConstant.TAKE_IMAGE_SUCCESS_KEY, false);
            if (success) {
                String imagePath = data.getStringExtra(ExternalConstant.FACE_IMAGE_PATH_KEY);
                Intent intent = new Intent(LoginActivity.this, RzActivity.class);
                Bundle bundle = new Bundle();
                bundle.putString("imagePath", imagePath);
                intent.putExtras(bundle);
                startActivity(intent);
                overridePendingTransition(R.anim.alpha_in, R.anim.alpha_out);
            }
        }
    }


}
